﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Configuration;

using Wxits.Data;
using Wxits.Helper;


public partial class Admin_Default : BasePage
{
    #region OnInitComplete
    /// <summary>
    /// 在页初始化后引发 System.Web.UI.Page.InitComplete 事件。
    /// </summary>
    /// <param name="e">包含事件数据的 System.EventArgs。</param>
    protected override void OnInitComplete(EventArgs e)
    {
        base.OnInitComplete(e);

        this._styleSheets.Add("JIndex.css");

        this._scripts.Add("~/JS/jQueryUI/jQuery-ui.custom.min.js");
        this._scripts.Add("~/JS/jQueryUI/jQuery.ui.autocomplete.js");
        this._scripts.Add("~/JS/jQueryUI/jQuery.effects.bounce.js");
        this._scripts.Add("~/JS/Shell/jQuery.plugins.js");
        this._scripts.Add("~/JS/Shell/FIndex.js");        
    }
    #endregion

	protected void Page_Load(object sender, EventArgs e)
	{
		if(!IsPostBack)
		{

            if (!DataCheck.ChenkAdminAuth())
            {
                Common.ShowAndRedirect(this, "登录超时，请重新登录" , "/admin/Login.aspx");
                return;
            }

            logobg.Attributes.Add("style", "background-image:url('../App_Themes/Flat/images/logo.png')");
            MenuUserName.InnerText = HelpCookie.Get("AdminUserName");



            showData();	
		}
	}

    private void showData()
    {

        DataTable dt = Data_Center.GetSysUserMenus(HelpCookie.GetDecrypt("AdminUid"));   //获取用户菜单
        string treeNodes = @" var zNodes = [";
        foreach (DataRow dr in dt.Rows)
        {
            string strNode = string.Format(@" id:'{0}',pId:'{1}',name:'{2}',targetURL:'{3}',iconSkin:'{4}', JQKey:'{5}', IsThird:'{6}'", dr["id"], dr["pid"], dr["name"], dr["Url"], dr["Icon"], dr["id"], dr["IsThird"]);
            treeNodes += "{" + strNode + "},";
        }
        treeNodes = treeNodes.TrimEnd(',');
        treeNodes += "];";

        string loginUser = "var loginUser = {\"uid\":\" uid \",\"user_id\":\" user_id \",\"user_name\":\" "+ HelpCookie.GetDecrypt("AdminUid") + " \"};\r\n";
        string oa_Time = string.Format("var OA_TIME = new Date({0},{1},{2},{3},{4},{5});\r\n",
                                       DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);

        this.ClientScript.RegisterStartupScript(this.GetType(), "msg", treeNodes + loginUser + oa_Time, true);
    }


    protected void logout_Click(object sender, EventArgs e)
    {
        DataCheck.Logout();
        Response.Redirect("/Admin/Login.aspx");
    }
}
